package cn.imoocc.weather1;

import com.imooc.weather.DayWeather;
import com.imooc.weather.HourWeather;
import com.imooc.weather.WeatherUtils;

import java.util.List;
import java.util.Scanner;

public class Application {
    public static void main(String[] args) {
        System.out.println("查询最近天气预报：");
        System.out.println("输入1，查询未来24小时的天气预报");
        System.out.println("输入2，查询未来15天的天气预报");
        System.out.println("请输入你的选择：");
        Scanner scanner = new Scanner(System.in);
        int i =scanner.nextInt();
        System.out.println("用户输入数字" + i);
        if (i == 1){
            System.out.print("请输入城市查询未来24小时的天气预报：");
            String city = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImplNew();
            List<HourWeather> weatherList = weatherUtils.w24h("d4d2ba1a6e954700a4d895910c4f1bf3",city);
            //System.out.println(weatherList);
            if(weatherList.isEmpty()){
                System.out.println("抱歉，未收录您查询的城市的天气数据。");
            }else{
                for(HourWeather hourWeather : weatherList){
                    String template = "%s月%s日%s时|%-3s|%-20s|%-8s|%-4s℃";
                    String row = String.format(template,new String[]{
                            hourWeather.getMonth(),
                            hourWeather.getDay(),
                            hourWeather.getHour(),
                            hourWeather.getWindDirection(),
                            hourWeather.getWindPower(),
                            hourWeather.getWeather(),
                            hourWeather.getTemperature()
                    });
                    System.out.println(row);
                }
            }
        }else if(i == 2){
            System.out.print("请输入城市查询未来15天的天气预报：");
            String city = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImplNew();
            List<DayWeather> dayWeathersList = weatherUtils.w3d("d4d2ba1a6e954700a4d895910c4f1bf3",city);
            //System.out.println(dayWeathersList);
            if(dayWeathersList.isEmpty()){
                System.out.println("抱歉，未收录您查询的城市的天气数据。");
            }else{
                for (DayWeather dayWeather : dayWeathersList){
                    String template = "%-2s年%-2s月%-2s日  |  气温： %s℃（日） %s℃（夜） |  天气： %s（日） %s℃（夜） |  风力：%s（日） %s（夜）";
                    String row = String.format(template, new String[]{
                            dayWeather.getYear(),
                            dayWeather.getMonth(),
                            dayWeather.getDay(),
                            dayWeather.getDayAirTemperature(),
                            dayWeather.getNightAirTemperature(),
                            dayWeather.getDayWeather(),
                            dayWeather.getNightWeather(),
                            dayWeather.getDayWindPower(),
                            dayWeather.getNightWindPower()
                    });
                    System.out.println(row);
                }
            }
        }else {
            System.out.println("数字超出范围");
        }
    }
}
